import { observable, action } from 'mobx';
import { ListStore } from '../listStore';
import {ShareStore } from '../shareStore'
import {ExchangeStore } from "../exchangeStore"
import {TaskInfoStore} from './taskInfoStore'
import * as  Apis from '../../apis/task';

class TaskExecuteStore  extends ListStore{	
	@observable topTabCount =[];
	@observable baseParams={};
	searchParams =  {
		tabkey: "all",
	}
	@observable rightMenu =[];
	conditiontype = {conditiontype:"execute"};
	
	@observable shareStore = new ShareStore();
	@observable exchangeStore = new ExchangeStore();
	@observable taskInfoStore = new TaskInfoStore();

	@observable isreloadWorkPlan = false;

	@action
	appendBaseParams=(params)=> {
        this.baseParams = {...this.baseParams,...params};
    }

	@action
    initDatas=(params = {})=> {
		let newParams = {...this.conditiontype,...params};
		this.topTabCount = this.topTabCount;    
		Apis.getTaskCondition(newParams).then(data=>{
			this.condition = data.condition;
			//根据高级搜索条件初始化form
			this.form && !this.form.isFormInit && this.form.initFormFields(data.condition);
		});
	}

	@action
    doSearch=(params={})=>{
		this.loading = true;
		 //获取表单的参数值
		 const searchParamsAd = this.form.getFormParams();
		 const newParams = { ...this.baseParams, ...this.searchParams, ...searchParamsAd, ...params };
        Apis.getTaskExecuteList(newParams).then(data=>{
			this.tableStore.getDatas(data.sessionkey,  params.current || 1);
			this.searchParams = { ...this.searchParams, ...params };
			this.topTabCount = data.tabnum;
			this.dataKey = data.sessionkey;
			this.rightMenu = data.rightMenus;
            this.loading = false;
        })
	}

	reLoad=()=>{
		this.doSearch();
	}
	
	@action
	setLoaded=()=>{
		this.isreloadWorkPlan= true;
	}

	onShowColumn=()=>{  //显示定制列
		this.tableStore.setColSetVisible(true);
		this.tableStore.tableColSet(true)
	}
	
	clearStatus=()=>{
		this.baseParams = {};
        this.searchParams = {tabkey: "all"};
        this.showSearchAd = false;
		this.clearFormFields();
		this.resetForm();
        this.condition = [];
        this.resetTable(true);
    }
}

export default TaskExecuteStore;